package com.zhouzj.task.springcloud.code.controller;

import com.zhouzj.task.springcode.code.api.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: zhouzhijun
 * @Date: 2021/8/5 15:16
 */
@RestController
@RequestMapping("/code")
public class CodeController {

    @Autowired
    private CodeService codeService;

    /**
     * 发送验证码
     *
     * @param email
     * @return java.lang.Boolean
     * @author zhouzhijun
     * @Date 15:17 2021/8/5
     */
    @GetMapping("/create/{email}")
    public Boolean send(@PathVariable("email") String email) {
        return codeService.send(email);
    }

    /**
     * 校验验证码是否正确
     *
     * @param email
     * @param code
     * @return java.lang.Boolean
     * @author zhouzhijun
     * @Date 15:19 2021/8/5
     */
    @GetMapping("/validate/{email}/{code}")
    public Boolean check(@PathVariable("email") String email, @PathVariable("code") String code) {
        return codeService.check(email,code);
    }
}
